import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { commonRoutes } from "./common"; // 公共路由
import { accountRoutes } from "./account"; // 账号模块
import { weixinRoutes } from "./weixin"; // 店员模块

const routes: Array<RouteRecordRaw> = [...commonRoutes, ...accountRoutes, ...weixinRoutes];
console.log(routes)
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('token');
  if (to.path === "/login") {
    next();
  } else {
    if (token) {
      next();
    } else {
      next({
        path: '/login'
      });
    }
  }
});

export default router;
